#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
const int MAXN=50;
const int INF=1e8;
int dp[MAXN*6];
struct B{
    int x,y,z;
    B(int _x=0,int _y=0,int _z=0):x(_x),y(_y),z(_z){}
};
vector<B> bs;
bool cmp(B a,B b){
    if(a.x==b.x){
        return a.y>b.y;
    }
    else{
        return a.x>b.x;
    }
}
bool fun(int i,int j){
    return (bs[i].x<bs[j].x && bs[i].y<bs[j].y);
}
int main(void){
    int n;
    int T=0;
    while(~scanf("%d",&n)){
        if(n==0){
            break;
        }
        int x,y,z;
        bs.clear();
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&x,&y,&z);
            bs.push_back(B(x,y,z));
            bs.push_back(B(y,x,z));
            bs.push_back(B(x,z,y));
            bs.push_back(B(z,x,y));
            bs.push_back(B(z,y,x));
            bs.push_back(B(y,z,x));
        }
        n=bs.size();
        sort(bs.begin(),bs.end(),cmp);
        /*
        for(int i=0;i<n;i++){
            printf("%d %d %d\n",bs[i].x,bs[i].y,bs[i].z);
        }
        */
        memset(dp,0,sizeof(dp));
        int ans=-INF;
        for(int i=0;i<n;i++){
            dp[i]=bs[i].z;
            for(int j=0;j<i;j++){
                if(fun(i,j)){
                    dp[i]=max(dp[i],dp[j]+bs[i].z);
                }
            }
            ans=max(ans,dp[i]);
        }
        ans=max(0,ans);
        printf("Case %d: maximum height = %d\n",++T,ans);
    }
    return 0;
}